package com.example.Lezedata.ui.dataPage.subVc;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.example.Lezedata.R;
import com.example.Lezedata.util.GBToast;

import bid.Bid;

public class ChequeListCell extends LinearLayout {
    public Bid.NodePool pool;
    private TextView textViewIP;
    public TextView textViewArea;
    public TextView textViewCopy;

    public static ChequeListCell newInstance(Context context , ViewGroup viewGroup) {
        ChequeListCell cell = (ChequeListCell)LayoutInflater.from(context).inflate(R.layout.cheque_list_cell,viewGroup,false);
        return cell;
    }

    public ChequeListCell(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        textViewIP = findViewWithTag("textViewIP");
        textViewArea = findViewWithTag("textViewArea");
        textViewCopy = findViewWithTag("textViewCopy");
        textViewCopy.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ClipboardManager clipboard = (ClipboardManager)getContext().getSystemService(Context.CLIPBOARD_SERVICE);
                ClipData clipData = ClipData.newPlainText(null,textViewArea.getText().toString());
                clipboard.setPrimaryClip(clipData);
                GBToast.shortToast("复制成功!");
            }
        });
    }

    public void setPool(Bid.NodePool pool) {
        this.pool = pool;
        textViewIP.setText(pool.getIpPub());
        textViewArea.setText(pool.getChequebookAddress());
    }
}
